"""
@name : ATM_test01
@author : maxueyan
@projectname: sanchuang
"""

users = [{'user_name':'chen','passwd':'123456','balance':2000},
        {'user_name':'ma','passwd':'123456','balance':3000},
        {'user_name':'shi','passwd':'123456','balance':5000}]

#登陆模块
def login(ausername,apasswd):
    global users
    for user_id in range(len(users)):
        if ausername == users[user_id]['user_name']:
            if apasswd == users[user_id]['passwd']:
                print("欢迎进入！")
        return user_id

#查询模块
def balance_money(user_id):
    global users
    print("你的余额为{}元".format(users[user_id]['balance']))

#存款模块
def deposit_money(user_id):
    global users
    money = int(input("请输入你要存入的金额："))
    users[user_id]['balance'] = users[user_id]['balance'] + money
    print("你已存款{}元，余额为{}元".format(money,users[user_id]['balance']))

#取款模块
def withdraw_money(user_id):
    global users
    money = int(input("请输入你要取出的金额："))
    users[user_id]['balance'] = users[user_id]['balance'] - money
    if users[user_id]['balance'] >= 0:
        print("你已取款{}元，余额为{}元".format(money,users[user_id]['balance']))
    elif users[user_id]['balance'] < 0:
        print("余额不足")
        users[user_id]['balance'] = int(money)

#主界面
while True:
    print("********欢迎使用sanchuang银行ATM*********")
    ausername = input("请输入你的用户名：")
    apasswd = input("请输入你的密码：")
    user_id = login(ausername,apasswd)
    if user_id < 0:
        continue
    while True:
        print("**********请选择业务********")
        print("**********1、取款**********")
        print("**********2、存款**********")
        print("**********3、查询**********")
        print("*********输入exit退出******")
        choose = input("请输入你的选择：")
        if choose == '1':
            withdraw_money(user_id)
        elif choose == '2':
            deposit_money(user_id)
        elif choose == '3':
            balance_money(user_id)
        elif choose == 'exit':
            break
        else:
            print("输入错误请重新输入！")





